import serial
from Xlib import X, display
from time import sleep

usbport = "/dev/ttyUSB0"

ser = serial.Serial(usbport, 1200)
n = 0

def moveMouse(x,y):
	 x = int(x) 
	 y = int(y) 
	 d = display.Display() 
	 s = d.screen() 
	 root = s.root 
	 root.warp_pointer(x,y) 
	 d.sync()
print 'Esperando'
ox=640
oy=400
#moveMouse(ox,oy)
posx = 0
posx_acumulada = 0
paso = 25
while n<500: 
	try:
		n = n+1 
		pos = ser.readline() 
		pos = pos.split('-')
	except: print 'No se mueve :(' 
	if (int(pos[0])>posx) and posx_acumulada < 1280 and (posx!=int(pos[0])):
		moveMouse(posx_acumulada + paso, pos[1])	
		posx = int(pos[0])
		posx_acumulada = posx_acumulada + paso
		#posy = pos[1] + posx
	elif int(pos[0])<posx and posx_acumulada > 0 and (posx!=int(pos[0])):
		moveMouse(posx_acumulada - paso, pos[1])	
		posx = int(pos[0])
		posx_acumulada = posx_acumulada - paso
		
		#posy = posy - pos[1]
	print pos[0], pos[1] 
	print 'Se Mueve :D'
			
	
